<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/jquery-3.6.0.min.js"></script>
    <link rel="stylesheet" href="/assets/vendors/nprogress/nprogress.css">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

    <link rel="stylesheet" href="./css/login.css">
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

</head>

<body>

    <div class="loginBox">
        <img class="avator" src="./img/default.png">
        <div class="form-group">
            <input id='email' name="email" type="email" class="form-control" id="exampleInputEmail1" placeholder="邮箱">
        </div>
        <div class="form-group">
            <input id='password' name="password" type="password" class="form-control" id="exampleInputPassword1" placeholder="密码">
        </div>
        <button class="btn btn-primary btn-block login-btn">登录</button>

    </div>

</body>
@@include('../home/common/base.html')
<script>
    $(function() {
        $('.login-btn').click(function() {
            const email = $('#email').val();
            const pwd = $('#password').val();
            if (!email.trim()) {
                alert('请输入邮箱')
                return
            }
            if (!pwd.trim()) {
                alert('请输入密码')
                return
            }
            const params = {
                email,
                password: pwd
            }
            $.ajax(`${baseUrl}/login`, {
                type: 'post',
                data: params,
                success: function(res) {
                    console.log('登录成功:', res);
                    const token = res.token;
                    if (token) {
                        localStorage.setItem('token', token);
                        location.href = '/admin/index.html'
                    } else {
                        console.log('登录失败');
                    }
                },
                error: function(err) {
                    console.log('登录失败:', err);
                }
            })
        })
    })
</script>

</html>